matlab中的cos(n^2)为什么不对

来源:百度知道 编辑:UC知道 时间:2024/06/21 22:53:21
cos(n^2)
??? Error using ==> mpower
Matrix must be square.

>> x=cos(n*n);
??? Error using ==> mtimes
Inner matrix dimensions must agree.
我不知道应该怎么办~
请教各位大虾
我是R2007

写成cos(n.^2)就可以了。。数组跟矩阵是不一样的。。

你可以给定n的值。
n=2;
x=n^2;
y=cos(x)
如果你的n值是变量的话,就在figure里看啊。可以这样:
n=-pi:0.1:pi;
y=(cos(2*n)+1)/2;
plot(n,y)
就行啦